<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>车辆添加</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../css/okadmin.css">
</head>

<body>
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title">
        <li class="layui-this">添加车辆</li>
        <li>批量添加车辆</li>
    </ul>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>车辆添加</legend>
    </fieldset>
    <div class="layui-tab-content" style="height: 100px;">
        <div class="layui-tab-item layui-show">
            <div class="addtea-con">
                <div class="from-con">
                    <div style="width: 60%;margin: 0 auto;">
                        <form class="layui-form" style="margin-left: -90px" action="" id="formaddtea">
                            <div class="layui-row">
                                <div class="layui-col-xs6">
                                    <div class="layui-form-item" style="margin-right: 15%">
                                        <label class="layui-form-label">I&#12288;&#12288;&#12288;D</label>
                                        <div class="layui-input-block">
                                            <input id="vehicleId" name="vehicleId" type="text"
                                                   style="float: left;position: relative;" lay-verify="required"
                                                   placeholder="ID" class="layui-input" autocomplete="off">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-xs6">
                                    <div class="layui-form-item" style="margin-left: 15%">
                                        <label class="layui-form-label">车&#12288;&#12288;牌</label>
                                        <div class="layui-input-block">
                                            <input id="licensePlateNumber" name="licensePlateNumber" type="text"
                                                   style="float: left;position: relative;" class="layui-input"
                                                   placeholder="车牌" lay-verify="required" autocomplete="off">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-row">
                                <div class="layui-col-xs6">
                                    <div class="layui-form-item" style="margin-right: 15%">
                                        <label class="layui-form-label">名&#12288;&#12288;称</label>
                                        <div class="layui-input-block">
                                            <input id="vehicleName" name="vehicleName" type="tel"
                                                   style="float: left;position: relative;" class="layui-input" lay-verify="required"
                                                   placeholder="名称" autocomplete="off">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-xs6">
                                    <div class="layui-form-item" style="margin-left: 15%">
                                        <label class="layui-form-label">类&#12288;&#12288;型</label>
                                        <div class="layui-input-inline">
                                            <select name="type" id="type" style="float: left;position: relative;">
                                                <option value="0">手动挡</option>
                                                <option value="1">自动挡</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-row">
                                <div class="layui-col-xs6">
                                    <div class="layui-form-item" style="margin-right: 15%">
                                        <label class="layui-form-label">所属教练</label>
                                        <div class="layui-input-inline">
                                            <select name="coachs" id="coachs" style="float: left;position: relative;" lay-search>
                                                <option value="">暂不选择</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-xs6">
                                    <div class="layui-form-item" style="margin-left: 15%">
                                        <label class="layui-form-label">价&#12288;&#12288;格</label>
                                        <div class="layui-input-block ">
                                            <input id="price" name="price" type="text"
                                                   style="float: left;position: relative;" class="layui-input"
                                                   placeholder=""
                                                   autocomplete="off">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-row">
                                <div class="layui-col-xs6">
                                    <div class="layui-form-item" style="margin-right: 15%">
                                        <label class="layui-form-label">备&#12288;&#12288;注</label>
                                        <div class="layui-input-block ">
                                            <input id="remark" name="remark" type="text"
                                                   style="float: left;position: relative;" class="layui-input"
                                                   placeholder=""
                                                   autocomplete="off">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-xs6">
                                </div>
                            </div>
                            <div class="layui-form-item" style="padding-bottom: 90px">
                                <div class="layui-input-block">
                                    <button type="button" id="addParent" lay-submit="" lay-filter="addParent"
                                            class="layui-btn layui-btn-normal layuiadmin-btn-list"
                                            style="float: right;margin-top: 50px"> 保 存
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-tab-item">
            <div class="importTeacher">
                <div class="layui-block importTeacher-con">
                    <div class="layui-form-item">
                        <button type="button" class="layui-btn leftbtn" id="test4">
                            <i class="layui-icon"></i>选择Excel文件
                        </button>
                        <a href="../../templateDownload/车辆信息导入模板.xlsx" type="reset"
                           class="layui-btn layui-btn-primary rightbtn">下载模板</a>
                    </div>
                </div>
                <table class="layui-hide" id="teacher"></table>
                <div class="model">
                    <script type="text/html" id="toolbarDemo">
                        <label>导入失败的数据</label>
                    </script>
                    <table class="layui-hide" id="teacherData"></table>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
<!--js逻辑-->
<script src="../../lib/layui/layui.js"></script>
<script src="../../js/jquery.min.js"></script>
<script src="../../js/application.js"></script>
<script>
    //用户信息导入
    layui.use(['element', 'okLayer', 'form'], function () {
        var $ = layui.jquery;
        var okLayer = layui.okLayer;
        var element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
        var form = layui.form;
        form.render();

        $("#test4").on('click', excelImport);

        function excelImport() {
            okLayer.open("用户信息导入", "vehicleImport.html", "90%", "90%", null, function () {

            });
        }

        myAjax(mainUri + '/vCoach/selects', {page: -1,possessVehicle:1}, function (datas) {
            var list = datas['data'];
            var option;
            for (var i = 0; i < list.length; i++) {
                {
                    option += "<option value='" + list[i]['coachId'] + "'>" + list[i]['fullname'] + "</option>";
                }
            }
            $("#coachs").append(option);
            form.render();
        })

        $("#addParent").on('click',function(){
            if ($('#vehicleId').val() == "" || $('#licensePlateNumber').val() == ""||$('#vehicleName').val() == "") {
                return;
            }
            layer.confirm("确定添加此车辆信息?", function (index) {
                var type = $("#type").find("option:checked").val();//类型
                var coach = $("#coachs").find("option:checked").val();//教练
                var data = {
                    vehicleId: $('#vehicleId').val(),
                    licensePlateNumber: $('#licensePlateNumber').val(),
                    vehicleName: $('#vehicleName').val(),
                    price: $('#price').val(),
                    remark: $('#remark').val(),
                    type: type,
                    "coach.coachId": coach
                };
                showloading(true)
                myAjax(mainUri + "/vehicle/insert", data, function (d) {
                    if (d.code == "0") {
                        layer.msg(d.msg)
                    } else {
                        alert(d.msg)
                    }
                })
                showloading(false)
            })
        })


    });

</script>
</html>